// Devein Game Engine
// Written by Danny Rodriguez
// Haxzs Development - 2008
// devein.gfx/main.h

#ifndef DEVEIN_GFX_MAIN_H
#define DEVEIN_GFX_MAIN_H

#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include "FreeImage.h"
#include <iostream>
#include <string.h>
#include <boost/function.hpp>

using namespace std;

namespace devein
{
	struct texture
	{
		int id;
	};

	struct font
	{
		char* name;
		int h;
	};

	// window class
	class gfx
	{
	private:
		// Variables
		HDC			hDC;			// Device Context
		HGLRC		hRC;			// Rendering Context
		HWND		hWnd;			// Window Handle
		HINSTANCE	hInstance;		// Window Instance
		bool		fullscreen;		// Fullscreen
		bool		active;			// Active
		bool		done;	// Done
		bool		keys[256];		// Keys
		int			width;			// Window Width
		int			height;			// Window Height
		float		fps;			// Window FPS
		string		fpsstring;		// Window FPS String
		MSG			msg;			// Message Handler
		GLuint		textures[1024];	// Textures

		// Private Prototypes

		void		drawscene();			// Private Drawing Function
		void		calcfps();				// Calculate FPS
		void		initialize();			// Private Initialization Function
		static		LRESULT CALLBACK swndproc(HWND, UINT, WPARAM, LPARAM);	// Static Window Procedure Loop
		LRESULT		wndproc(HWND, UINT, WPARAM, LPARAM);					// Real Window Procedure
		void		draw2dwindows();		// Private 2D Window drawing

		int			textureload(char* t);
		int			fontload(char* t, int h);

	public:

		// Public Prototypes

		gfx();							// Constructor

		int					msgloop();		// Enter Message Loop

		// For textures
		int					loadtexture(int id, char* textureFile);
		void				applytexture(int id);

		// For fonts
		int					loadfont(int id, char* fontFilename, int h);
		void				text(int fontid, char* text, int x, int y, int r = 255, int g = 255, int b = 255);

		inline int			getwidth()		{ return width; }		// Get Window Width
		inline int			getheight()		{ return height; }		// Get Window Height
		inline bool			getactive()		{ return active; }		// Get Active Status
		inline HGLRC		getrc()			{ return hRC; }			// Get Rendering Context
		inline HWND			gethwnd()		{ return hWnd; }		// Get Window Handle
		inline HINSTANCE	getinstance()	{ return hInstance; }	// Get Instance
		inline HDC			gethdc()		{ return hDC; }			// Get Device Context

		inline void			setfullscreen(bool fsflag)	{ fullscreen = fsflag; }	// Set Fullscreen Flag
		inline void			sethwnd(HWND newhwnd)		{ hWnd = newhwnd; }			// Set Window Handle

		GLvoid				kill(GLvoid);				// Kill GL Window
		GLvoid				resize(GLsizei, GLsizei);	// Resize Window

		bool				create(char* title, int width, int height, int bits);	// Create Window

		boost::function<void (void)>	draw;
		boost::function<int (void)>		init;

		inline int			getfps() { return fps; }
		inline const char *	getfpsstring() { return fpsstring.c_str(); }
	};


}

#endif

